﻿using System;
using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.Threading;
namespace alarm
{
    public delegate void RingEventHandler(object sender, MyalarmArgs e);//声明委托类型
    
    public class alarm
    {
        public event RingEventHandler ring;//声明事件
        public virtual void run(MyalarmArgs e)//调用事件
        {
            if (ring != null)
            {
                ring(this, e);
            }
        }
        
    }
    public class MyalarmArgs : EventArgs
    {
        public MyalarmArgs() { }
    }
    public class ring
    {
        public void ringing(object sender, MyalarmArgs e) {//事件处理方法
            Console.WriteLine("The clock is ringing");
        }

    }
    public class tick
    {
        public void ticking(object sender,MyalarmArgs e)
        {
            Console.WriteLine("The clock is ticking!");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            alarm alarm1 = new alarm();
            MyalarmArgs e = new MyalarmArgs();
            ring ring1 = new ring();
            tick tick1 = new tick();
            alarm1.ring += new RingEventHandler(ring1.ringing);//注册事件
            alarm1.ring += new RingEventHandler(tick1.ticking);
            for(; ; )
            {
                Thread.Sleep(1000);
                alarm1.run(e);//每秒触发调用一次事件，每秒滴答和响铃一次

            }
        }

       

    }
}
